package com.woniu.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.common.CommonResult;
import com.woniu.dto.ActivityComplainDTO;
import com.woniu.service.ActivityComplainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/ac_complain")
@Api(tags ="活动投诉")
public class ActivityComplainController {

    @Autowired
    private ActivityComplainService acComplainService;

    /**
     * 分页查询活动投诉的列表信息
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    @RequiresPermissions("sys:acc:list")
    @ApiOperation(value = "活动投诉列表分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页数",defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize",value = "每页数据条数",defaultValue = "5")
    })
    public CommonResult list(@RequestParam(value = "page",defaultValue = "1",required = false)Integer currentPage,
                             @RequestParam(value = "limit",defaultValue = "5",required = false)Integer pageSize){
        PageInfo info=null;
        try {
            List<ActivityComplainDTO> list=acComplainService.findByPage(currentPage,pageSize);
            info=new PageInfo(list);
            return CommonResult.success(info);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed();
        }
    }
    /**
     * 导航到回复投诉的页面
     * @param id
     * @return
     */
    @RequestMapping("/reply/{id}")
    @ResponseBody
    @RequiresPermissions("sys:acc:reply")
    @ApiOperation(value = "导航到回复投诉的页面")
    @ApiImplicitParam(name = "id",value = "投诉列表ID",dataType = "Integer")
    public ModelAndView reply(@PathVariable("id")Integer id){
        ActivityComplainDTO activityComplainDTO=acComplainService.findById(id);
        ModelAndView model=new ModelAndView("sys/ac_reply");
        model.addObject("ActivityComplainDTO",activityComplainDTO);
        return model;
    }

    /**
     * 投诉回复内容的添加
     * @param activityComplainDTO
     * @return
     */
    @PutMapping("/editComplain")
    @ResponseBody
    @ApiOperation(value = "投诉回复内容的添加")
    @ApiImplicitParam(name = "activityComplainDTO",value = "回复内容")
    public CommonResult addReply(ActivityComplainDTO activityComplainDTO){
        try {
            acComplainService.addReply(activityComplainDTO);
            return CommonResult.success("回复上传成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("回复上传失败!");
        }

    }

    /**
     * 搜索功能
     * @param nickName
     * @param title
     * @return
     */
    @RequestMapping("/select")
    @ResponseBody
    @ApiOperation(value = "活动投诉页面搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nickName",value = "用户姓名"),
            @ApiImplicitParam(name = "title",value = "活动标题")
    })
    public CommonResult select(String nickName,String title){
        PageInfo info=null;
        try {
            List<ActivityComplainDTO> list=acComplainService.select(nickName,title);
            info=new PageInfo(list);
            return CommonResult.success(info);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed();
        }

    }

}
